Skip to content

Write config temp files next to the target so the move stays atomic - #6630

Open
dekrom wants to merge 1 commit into
MeteorDevelopment:masterfrom
dekrom:fix/atomic-config-save
Open

dekrom wants to merge 1 commit into
MeteorDevelopment:masterfrom
dekrom:fix/atomic-config-save

Conversation

@dekrom

@dekrom dekrom commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Type of change

  • Bug fix
  • New feature

Description

System#save writes to a temp file and then moves it over the target, which is the right shape,
but the temp file is created with no directory argument:

tempFile = Files.createTempFile(MeteorClient.MOD_ID, file.getName());

so it lands in java.io.tmpdir while the target is under the game directory. When those are
different filesystems the atomic move can't work, Files.move throws
AtomicMoveNotSupportedException, and the fallback is StreamUtils.copy, a plain
Files.copy(..., REPLACE_EXISTING). That deletes the old file and writes the new one in place,
so a kill or a full disk part way through leaves the config missing or cut short, and the
IOException only ends up in the log.

/tmp being its own tmpfs mount is the systemd default, and on Windows %TEMP% is often on a
different drive than the instance, so for a lot of people this isn't the rare fallback, it's every
save.

Resolving the destination first and creating the temp file next to it puts the move back on one
filesystem, so it stays atomic. The copy fallback stays for anything exotic. The temp file now
ends in .tmp instead of the target's name, so if one is ever left behind in a profile folder
nothing that scans for *.nbt picks it up.

Related issues

None that I found.

How Has This Been Tested?

Checked that /tmp is a separate tmpfs mount from the game directory on my machine, so every save
there went through the copy. With the change, a full quit writes every config, including the
profile and waypoint files, and leaves no temp files behind. I haven't killed the process mid-save
to produce a broken config.

Checklist:

  • My code follows the style guidelines of this project.
  • I have added comments to my code in more complex areas.
  • I have tested the code in both development and production environments.

@dekrom
dekrom force-pushed the fix/atomic-config-save branch from 96445b8 to 33b1972 Compare December 1, 2026 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant